<template>
  <div style="padding: 400px; padding-left: 600px; background-color: white">
    <el-form
        :label-position="labelPosition"
        label-width="100px"
        :model="formLabelAlign"
        style="max-width: 460px"
    >
      <el-form-item label="店铺Id">
        <el-input v-model="shopId" />
      </el-form-item>
      <el-form-item label="可抵金额">
        <el-input v-model="amount" />
      </el-form-item>
      <el-form-item label="价格">
        <el-input v-model="price" />
      </el-form-item>
      <el-form-item label="数量">
        <el-input v-model="number" />
      </el-form-item>
    </el-form>
    <div style="padding-left: 400px; padding-top: 20px">
      <el-button link type="primary" size="large" @click="addCoupon">
        确定
      </el-button>
      <el-button link type="primary" size="large" @click="back">
        返回
      </el-button>
    </div>
  </div>

</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import type { FormProps } from 'element-plus'
import {useRouter} from "vue-router";
const router = useRouter();
const labelPosition = ref<FormProps['labelPosition']>('right')
import api from '../api/api';
import {ElMessage} from "element-plus";
const shopId = ref("")
const amount = ref(0.0)
const price = ref(0.0)
const number = ref(0.0)

const back = () => {
  router.push('/')
}
const addCoupon = () => {
  const data = {
    shopId: shopId.value,
    amount: amount.value,
    price: price.value,
    number: number.value,
  }
  api.post('/api/coupon/addCoupon', data).then((response => {
    ElMessage({
      type: 'success',
      message: '添加成功',
    })
    router.push('/')
  }))
}
const formLabelAlign = reactive({
  name: '',
  region: '',
  type: '',
})
</script>
